{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
    "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
    "execution": {
     "iopub.execute_input": "2025-03-22T20:59:53.933271Z",
     "iopub.status.busy": "2025-03-22T20:59:53.932859Z",
     "iopub.status.idle": "2025-03-22T21:00:01.992857Z",
     "shell.execute_reply": "2025-03-22T21:00:01.991502Z",
     "shell.execute_reply.started": "2025-03-22T20:59:53.933240Z"
    },
    "trusted": true
   },
   "outputs": [],
   "source": [
    "from torch import nn\n",
    "from torchvision.models import resnet18, ResNet18_Weights, inception_v3, Inception_V3_Weights, vit_b_16, ViT_B_16_Weights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-22T21:10:54.312077Z",
     "iopub.status.busy": "2025-03-22T21:10:54.311724Z",
     "iopub.status.idle": "2025-03-22T21:10:54.319446Z",
     "shell.execute_reply": "2025-03-22T21:10:54.318272Z",
     "shell.execute_reply.started": "2025-03-22T21:10:54.312049Z"
    },
    "trusted": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Downloading: \"https://download.pytorch.org/models/resnet18-f37072fd.pth\" to /Users/summy/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth\n",
      "100%|██████████| 44.7M/44.7M [02:58<00:00, 263kB/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "11689512"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = resnet18(weights=ResNet18_Weights.DEFAULT)\n",
    "sum(param.numel() for param in model.parameters() if param.requires_grad)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'generator' object has no attribute 'device'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparameters\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdevice\u001b[49m\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'generator' object has no attribute 'device'"
     ]
    }
   ],
   "source": [
    "model.parameters().device"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-22T21:10:59.327223Z",
     "iopub.status.busy": "2025-03-22T21:10:59.326802Z",
     "iopub.status.idle": "2025-03-22T21:10:59.334036Z",
     "shell.execute_reply": "2025-03-22T21:10:59.333013Z",
     "shell.execute_reply.started": "2025-03-22T21:10:59.327192Z"
    },
    "trusted": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11689512"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.requires_grad_(False)\n",
    "sum(param.numel() for param in model.parameters())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-22T21:11:22.407790Z",
     "iopub.status.busy": "2025-03-22T21:11:22.407428Z",
     "iopub.status.idle": "2025-03-22T21:11:22.415322Z",
     "shell.execute_reply": "2025-03-22T21:11:22.414204Z",
     "shell.execute_reply.started": "2025-03-22T21:11:22.407763Z"
    },
    "trusted": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for param in model.parameters():\n",
    "\tparam.requires_grad_(False)\n",
    "sum(param.numel() for param in model.parameters() if param.requires_grad)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-22T21:11:59.512793Z",
     "iopub.status.busy": "2025-03-22T21:11:59.512470Z",
     "iopub.status.idle": "2025-03-22T21:11:59.521279Z",
     "shell.execute_reply": "2025-03-22T21:11:59.520208Z",
     "shell.execute_reply.started": "2025-03-22T21:11:59.512769Z"
    },
    "trusted": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "131328"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fc = nn.Linear(model.fc.in_features, 256)\n",
    "sum(param.numel() for param in model.parameters() if param.requires_grad)"
   ]
  }
 ],
 "metadata": {
  "kaggle": {
   "accelerator": "none",
   "dataSources": [
    {
     "datasetId": 6936383,
     "sourceId": 11123105,
     "sourceType": "datasetVersion"
    }
   ],
   "dockerImageVersionId": 30918,
   "isGpuEnabled": false,
   "isInternetEnabled": true,
   "language": "python",
   "sourceType": "notebook"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
